package socket;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketServer {
	public static void main(String[] args) {
		ServerSocket serverSocket = null;
		Socket socket = null;
		OutputStream os = null;
		InputStream is = null;
		
		//监听端口
		int port = 8888;
		
		try{
			serverSocket = new ServerSocket(port);
			System.out.print("服务器启动！");
			int i = 0;
			while(true){
				socket = serverSocket.accept();
				//启动线程
				new LogicThread(socket);
				
				System.out.println("收到第" + ++i + "个用户访问");
			}
			
			
			/*//获取连接
			socket = serverSocket.accept();
			
			//获取数据
			is = socket.getInputStream();
			byte[] b = new byte[1024];
			int n = is.read(b);
			
			//输出
			System.out.println("客户端发送的+" + new String( b, 0, n));
			
			//反馈
			os = socket.getOutputStream();
			os.write(b, 0, n);*/
			
		}catch (Exception e) {
            e.printStackTrace();
		}finally{
			try{
				os.close();
				is.close();
				socket.close();
			}catch(Exception e){}
		}
	}
}
